import Feature from "../Feature";
import { Utils } from "../../utils";
import { ClassName, CtrlType, Events } from "@/Constants";
import Rect from "./Rect";

// 圆形元素
class Circle extends Rect {

    constructor(x: number = 0, y: number = 0, width: number = 10, height?: number) {   // 相对坐标
        if (!height) height = width;
        super(x, y, width, height);
        this.pointArr = Utils.getCirclePoints(x, y, width, height, 0);
        this.position.x = x;
        this.position.y = y;
        this.size.width = width;
        this.size.height = height;
        this.className = ClassName.CIRCLE;
        this.isClosePath = true;
        this.ctrlTypes = [CtrlType.WIDTH_CTRL, CtrlType.HEIGHT_CTRL, CtrlType.SIZE_CTRL, CtrlType.ANGLE_CTRL];  // 可用的控制点类型有哪些
    }

    override setSize = (width: number = this.size.width, height: number = this.size.height) => {
        this.size.width = width;
        this.size.height = height;
        this.pointArr = Utils.getCirclePoints(this.position.x, this.position.y, this.size.width, this.size.height, this.angle);
        this.dispatch(new CustomEvent(Events.RESIZE, { detail: { target: this } }))
    }

}

export default Circle;